#!/bin/sh
# Marc 'rhaamo' Lagrange <rhaamo@gruik.at> -- WMFS status.sh script
# Inspired by - https://github.com/bacardi55/dotfiles/blob/master/wmfs/status.sh
# - http://pastebin.com/f47d05f9a

_date() {
    date="`LC_ALL="fr_FR.UTF-8" date '+%A %d %B %r'`"
}

_memory() {
    memory_free="`free -m | awk '/Mem:/ { print $4 }'`"
    memory_total="`free -m | awk '/Mem:/ { print $2 }'`"
    memory="$memory_free/$memory_total Mo"
}

_wireless() {
    WLAN=`awk '/wlan/' /proc/net/wireless`
    QUALITY=`awk '/wlan0/ { print $3 }' /proc/net/wireless|sed -e 's/\.$//'`
    ESSID=`iwconfig wlan0 | awk '/ESSID/ { print $4 }'|sed -e 's/ESSID:"//'|sed -e 's/"$//'`
    if [ "${WLAN}" == "" ]; then
wireless="Wifi off"
    else
wireless="${ESSID}:${QUALITY}%"
    fi
}

_battery() {
    REM=`awk '/remaining capacity/ { print $3 }' /proc/acpi/battery/BAT0/state`
    LAST=`awk '/last full/ { print $4}' /proc/acpi/battery/BAT0/info`
    bat_percent=$(echo $REM $LAST | awk '{printf "%d", ($1/$2)*100'})

    bat_acpi=`cat /sys/class/power_supply/BAT0/status`
    if [ "$bat_acpi" = "Discharging" ]; then
bat_state="↓"
    elif [ "$bat_acpi" = "Charging" ]; then
bat_state="↑"
    fi
    # Blink if % < 15 (since my battery is mostly dead i will probably never see the blink :D)
    if [ "$bat_percent" -lt "15" ]; then
bat_fail=1
if [ "`cat /tmp/batteryfail`" ]; then
color="\\#ff6b6b\\"
echo 0 > /tmp/batteryfail
else
color="\\#435e87\\"
echo 1 > /tmp/batteryfail
fi
else
bat_fail=0
color="\\#C0C0C0\\"
    fi
battery="$color Bat. $bat_percent% $bat_state"
}

_separateur() {
    separateur="•"
}

statustext() {
    # concat args
    for arg in $@; do
_${arg}
        args="${args} `eval echo '$'$arg`"
    done
wmfs -s 0 "$args"
}

statustext separateur wireless separateur battery separateur memory separateur date